#include <iostream>
#include <memory>
#include <vector>

using std::cout;
using std::endl;
using std::unique_ptr;
using std::vector;

class Point
{
public:
    Point(int ix = 0, int iy = 0)
    : _ix(ix)
    , _iy(iy )
    {
        cout << "Point(int = 0, int = 0)" << endl;
    }

    void print() const
    {
        cout << "(" << _ix 
             << ", " << _iy
             << ")" << endl;
    }

    ~Point()
    {
        cout << "~Point()" << endl;
    }

private:
    int _ix;
    int _iy;
};

void test()
{
    unique_ptr<int> up(new int(10));
    cout << "*up = " << *up << endl;
    cout << "up.get() = " << up.get() << endl;

    /* unique_ptr<int> up2 = up;//error */
    unique_ptr<int> up3(new int(200));
    cout << "*up3 = " << *up3 << endl;

    cout << endl;
    /* up3 = up;//error */

    cout << endl << "unique_ptr作为容器元素" << endl;
    vector<unique_ptr<int>> vec;
    /* vec.push_back(up);//error,要执行unique_ptr拷贝构造函数 */
    vec.push_back(std::move(up));//要执行unique_ptr移动构造函数
    vec.push_back(std::move(up3));
    vec.push_back(unique_ptr<int>(new int(100)));
}

void test2()
{
    unique_ptr<Point> up(new Point(1, 2));
    vector<unique_ptr<Point>> vec;
    vec.push_back(std::move(up));//要执行unique_ptr移动构造函数
    vec.push_back(unique_ptr<Point>(new Point(100)));

}

int main(int argc, char *argv[])
{
    test2();
    return 0;
}

